<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>const关键字</title>
  </head>
  <body>
    <div></div>
    <script>
      /*
        const关键字
        */
      //1、声明必须赋初始值
      //const A; //Uncaught SyntaxError: Missing initializer in const declaration

      //2、常量一旦声明不可改变，一般定义常量使用大写（开发规范)
      const B = "商信政通"
      // console.log(B);
      //B = "商信" //Uncaught SyntaxError: Identifier 'B' has already been declared

      //3、先声明再使用，作用域和let一样，都是块级作用域
      // if(true){
      //     //console.log(C);//Uncaught ReferenceError: C is not defined
      //     const C = "商信政通";
      //     console.log(C);
      // }
      // console.log(C);// Uncaught ReferenceError: C is not defined

      //4、对象常量，内容可变，引用的地址不可变
      const USER = {
        //变量的引用地址不能变，对象里面的属性可改变
        name: "小明",
        age: 12,
      }
      //console.log(USER.name,USER.age)
      // USER = {//Uncaught TypeError: Assignment to constant variable.
      //     name:'小李'
      // }
      // USER.age = 14;
      // console.log(USER.name,USER.age)//小明,14
    </script>
  </body>
</html>
